﻿using System;
using System.Linq;
using FluentValidation;

namespace LINQPad.OpenAccess.UI.ViewModel.Validators
{
    /// <summary>
    /// Validator for <see cref="BackendSettingsViewModel"/> instances
    /// </summary>
    public class BackendSettingsViewModelValidator : AbstractValidator<BackendSettingsViewModel>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BackendSettingsViewModelValidator" /> class.
        /// </summary>
        public BackendSettingsViewModelValidator( )
        {
            // selected backend
            this.RuleFor( b => b.SelectedBackend )
                .NotNull( )
                .WithMessage( "no backend selected !" )
                .Unless( b => b.UseDefaultBackend );

            // selected provider
            this.RuleFor( b => b.SelectedProviderName )
                .NotEmpty( )
                .WithMessage( "no provider selected !" )
                .Unless( b => b.UseDefaultBackend );
        }
    }
}
